module EventEditor
  module Route
    class PassDialog
      def self.show(base, &func)
       dialog = Gtk::Dialog.new("Move Wait",
               base,
               Gtk::Dialog::MODAL |
               Gtk::Dialog::DESTROY_WITH_PARENT,
               ["OK", Gtk::Dialog::RESPONSE_OK],
               ["Cancel", Gtk::Dialog::RESPONSE_CANCEL]
               )

        vbox = Gtk::VBox.new
        vbox.set_border_width(5)
          
        vbox.add(@pass_tile = Gtk::CheckButton.new('pass(tile)'))
        vbox.add(@pass_character = Gtk::CheckButton.new('pass(character)'))
        vbox.add(@pass_event = Gtk::CheckButton.new('pass(event)'))
        
        dialog.vbox.add(vbox)
        dialog.vbox.show_all

        # run
        dialog.run do |response|
          if response == Gtk::Dialog::RESPONSE_OK
            func.call(@pass_tile.active?, @pass_character.active?, @pass_event.active?)
          else
            func.call(:cancel, :cancel, :cancel)
          end
          dialog.destroy
        end
      end

      def self.command_to_s(args)
        t = [{true => 'Tile=on, ', false => "Tile=off, "}, {true => 'Chara=on, ', false => 'Chara=off, '}, {true => 'Event=on', false => 'Event=off'}]
        return t[0][args[1]] + t[1][args[2]] + t[2][args[3]]
      end
    end
  end
end